import Mock from "mockjs";
import Common from "@/utils/common";

export default {
  fetchList: req => {
    let page = Common.getUrlParam("page", req.url);
    let status = Common.getUrlParam("status", req.url) * 1;
    let list = [];
    for (let i = 10 * (page - 1) + 1; i <= 10 * page; i++) {
      list.push(
        Mock.mock({
          id: i,
          username: Mock.Random.name(),
          nickname: Mock.Random.cname(),
          status:
            status === 1 ? 1 : status === 0 ? 0 : Mock.Random.integer(0, 1),
          created_at: Mock.Random.now(),
          updated_at: Mock.Random.now()
        })
      );
    }
    return {
      code: "200",
      msg: "操作成功",
      data: {
        total: 1000,
        page: 1,
        length: 10,
        list
      }
    };
  },
  setStatus: () => {
    return {
      code: "200",
      msg: "操作成功",
      data: {}
    };
  },
  fetchDetail: req => {
    let id = Common.getUrlParam("id", req.url);
    return {
      code: "200",
      msg: "操作成功",
      data: {
        id,
        username: "admin",
        nickname: "管理员",
        status: 1,
        created_at: "2019-05-13 9:00:00",
        updated_at: "2019-05-13 9:00:00"
      }
    };
  },
  store: req => {
    console.log(req);
    return {
      code: "200",
      msg: "创建成功",
      data: {}
    };
  },
  save: req => {
    console.log(req);
    return {
      code: "200",
      msg: "更新成功",
      data: {}
    };
  }
};
